﻿
var dialogEx = function (divId, title, okText, closeText, onOk, static) {
    var dialog = _createExDialog(divId.substr(1) + 'dialogEx', okText, closeText, "dialogExClass", divId);
    var over = dialog.overlay({ top: 100,
        mask: { color: 'gray', loadSpeed: 0, opacity: 0.5, maskId: divId.substr(1) + "ExMask" },
        closeOnClick: false, load: true, oneInstance: false
    });

    $("h2 .title", dialog).text(ifNull(title, " "));
    //$(".text", dialog).html($(divId).show());

    var subDiv = $(divId);
    if (subDiv.width() > dialog.width() - 30)
        dialog.width(subDiv.width() + 60);
    over.load();
    dialog.css("left", ($(window).width() - dialog.width()) / 2);

    _setBgiframe('#' + divId.substr(1) + "ExMask");
    $('.ok', dialog).unbind('click').attr('disabled', false);
    if (onOk)
        $('.ok', dialog).bind('click', function () {
            $(this).attr('disabled', true);
            onOk(dialog)
        });
    return dialog;
};

/* jquery tools ui ext */
var _createExDialog = function (id, okText, closeText, clsName, divId) {
    var dialog = $('#' + id + 'Div');
    if (dialog.length == 0) {
        dialog = $('<div>')
        .attr("id", id + "Div")
        .addClass(ifNull(clsName, id + "Class"))
        .addClass("crmdlg")
        .append("<div><h2><a class='close closebtn'>[×]</a><span class='title'></span></h2><p class='text'></p><p><input type='button' class='button ok' /> <input type='button' class='button close'/></p></div>");
        if (divId) {
            $(divId).after(dialog);
            $(".text", dialog).html($(divId).show());
        }
        else
            $('body').append(dialog);
        if (closeText)
            $("p .close", dialog).val(closeText);
        else
            $("p .close", dialog).hide();
        if (okText)
            $("p .ok", dialog).val(okText);
        else
            $("p .ok", dialog).hide();
        if ($.fn.bgiframe) {
            dialog.bgiframe();
        }
    }
    return dialog;
};

/*
*   增加后台背景模板
*/
var _setBgiframe = function (id) { if ($.fn.bgiframe) { $(ifNull(id, '#exposeMask')).bgiframe(); } };
